package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppRoomLaHei;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AfterRoomLaHeiDao.java
 * @Description TODO
 * @createTime 2021年07月28日 18:31:00
 */
@Repository
public class AfterRoomLaHeiDao extends BaseDao<AppRoomLaHei> {

    /**
     * 新增/修改
     * @param appRoomLaHei
     */
    public void saveOrUpdate(AppRoomLaHei appRoomLaHei) {
        if (appRoomLaHei!=null && appRoomLaHei.getId() != null &&  appRoomLaHei.getId() > 0) {
            this.update(appRoomLaHei);
        } else {
            appRoomLaHei.setId(this.add(appRoomLaHei));
        }
    }

    /**
     * 综合查询
     */
    public List<AppRoomLaHei> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_room_lahei where 1=1 ");
        if (StringEx.isNotNull(paramap.get("roomid"))) {
            str.append(" and roomid = ? ");
            list.add(paramap.get("roomid"));
        }

        if (StringEx.isNotNull(paramap.get("roomname"))) {
            str.append(" and roomname = ? ");
            list.add(paramap.get("roomname"));
        }

        if (StringEx.isNotNull(paramap.get("nick"))) {
            str.append(" and nick = ? ");
            list.add(paramap.get("nick"));
        }

        String sql = str.toString();
        return this.queryList(sql, list, AppRoomLaHei.class, splitPageBean);
    }

    /**
     * 根据房间ID和用户ID查询拉黑名单信息
     * @param roomid
     * @param userid
     * @return
     */
    public AppRoomLaHei getByRoomidAndUserid(Integer roomid, Integer userid) {
        if(roomid==null || roomid<=0 || userid==null || userid<=0){
            return null;
        }
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_room_lahei where roomid = ? and userid = ? ");
        list.add(roomid);
        list.add(userid);
        String sql = str.toString();
        return this.queryObj(sql,list,AppRoomLaHei.class);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(Integer id) {
        if (id == null || id<=0) {
            return;
        }
        ArrayList<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("delete from app_room_lahei where id = ?");
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }


}